//
//  GWComposePhotoView.m
//  新浪微博
//
//  Created by qianfeng on 16/1/15.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWComposePhotoView.h"

@implementation GWComposePhotoView
-(void)addImage:(UIImage *)image
{
    UIImageView *imageView =[[UIImageView alloc]init];
    imageView.image =image;
    imageView.contentMode =UIViewContentModeScaleAspectFill;
    imageView.clipsToBounds =YES;
    [self addSubview:imageView];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    NSInteger count =self.subviews.count;
    CGFloat margin =10;
    NSInteger maxcolsPreRow =3;
    CGFloat imageViewW = (self.superview.width-margin*(maxcolsPreRow+1))/maxcolsPreRow;
    CGFloat imageViewH =imageViewW;
    
    for (int i =0; i<count; i++) {
        NSInteger col= i%maxcolsPreRow;
        NSInteger row =i/maxcolsPreRow;
        UIImageView *imageView =self.subviews[i];
        imageView.frame =CGRectMake(margin+(margin+imageViewW)*col,(margin+imageViewW)*row , imageViewW, imageViewH);
    }
}
-(NSMutableArray *)images
{
    _images =[NSMutableArray array];
    for (UIImageView *imageView in self.subviews) {
        [_images addObject:imageView.image];
    }
    return _images;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
